package com.example.x6.configurationmaintenance.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.util.Log;
import com.example.x6.configurationmaintenance.BoardCaseReceiver.BoardCaseReceiverUtil;
import com.example.x6.configurationmaintenance.Dialog.MessageDialog;
import com.example.x6.configurationmaintenance.Dialog.PowerOffDialog;
import com.example.x6.configurationmaintenance.Interface.OnDensityChangedListener;
import com.example.x6.configurationmaintenance.Interface.OnRotateChangedListener;
import com.example.x6.configurationmaintenance.Module.BootanimationManager;
import com.example.x6.configurationmaintenance.Module.ComposePolicyManager;
import com.example.x6.configurationmaintenance.Module.DensityManager;
import com.example.x6.configurationmaintenance.Module.RotateManager;
import com.example.x6.configurationmaintenance.Module.SecondRotateManager;
import com.example.x6.configurationmaintenance.R;
import com.example.x6.configurationmaintenance.Service.RebootService;
import com.example.x6.configurationmaintenance.Service.ServiceDaemonService;
import com.example.x6.configurationmaintenance.Utils.PowerKitDaemonUtil;

public class MainActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
    private final String TAG = getClass().getSimpleName();
    private BootanimationManager bootanimationManager;
    private ComposePolicyManager composePolicyManager;
    private ListPreference compose_policy;
    private String densityKey = null;
    private DensityManager densityManager;
    private ListPreference density_main;
    private PreferenceCategory display_mian;
    private Preference explain_main;
    private Preference export_syslog_main;
    private PreferenceCategory help_main;
    private Preference kitkat_main;
    private Preference overscan_main;
    private PowerKitDaemonUtil powerKitDaemonUtil;
    private Preference replace_bootanimation_main;
    private Preference resolution_mian;

    private String rotateKey = null;
    private RotateManager rotateManager;
    private ListPreference rotate_main;
    private SecondRotateManager secondRotateManager;
    private ListPreference second_rotate_main;
    private Preference servicedaemon_main;
    private PreferenceCategory system_main;
    private Preference update_main;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.main);
        this.densityManager = new DensityManager();
        this.rotateManager = new RotateManager();
        this.secondRotateManager = new SecondRotateManager();
        this.bootanimationManager = new BootanimationManager();
        this.composePolicyManager = new ComposePolicyManager();
        startService();
        this.powerKitDaemonUtil = new PowerKitDaemonUtil(this);
        this.powerKitDaemonUtil.startDaemon();
        new BoardCaseReceiverUtil();
        initView();
        initEvent();
    }

    private void startService() {
        startService(new Intent(this, RebootService.class));
        startService(new Intent(this, ServiceDaemonService.class));
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
    }

    /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARNING: Code restructure failed: missing block: B:49:0x0209, code lost:
        if (r5.equals(com.example.x6.configurationmaintenance.Common.BuildModel.RK3288_AND71) != false) goto L_0x0217;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void initView() {
        /*
        // Method dump skipped, instructions count: 680
        */
//        throw new UnsupportedOperationException("Method not decompiled: com.example.x6.configurationmaintenance.Activity.MainActivity.initView():void");
        overscan_main=findPreference("overscan_main");
        replace_bootanimation_main=findPreference("replace_bootanimation_main");
        explain_main=findPreference("explain_main");
        kitkat_main=findPreference("kitkat_main");
        update_main=findPreference("update_main");
        export_syslog_main=findPreference("export_syslog_main");
        servicedaemon_main=findPreference("service_daemon");
        resolution_mian=findPreference("resolution_mian");
//        system_main=findPreference("system_main");
        second_rotate_main= (ListPreference) findPreference("second_rotate_main");
        density_main= (ListPreference) findPreference("density_main");
        compose_policy= (ListPreference) findPreference("compose_policy");
        rotate_main= (ListPreference) findPreference("rotate_main");
        compose_policy= (ListPreference) findPreference("compose_policy");
        // 设置summary为所选中的值列表值

        if(rotate_main.getEntries()!=null) {
            second_rotate_main.setSummary(second_rotate_main.getEntry());//初始化时设置summary
        }
    }

    private void initEvent() {
        this.overscan_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass1 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(OverscanActivity.class);
                return true;
            }
        });
        this.replace_bootanimation_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass2 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(ReplaceBootanimation.class);
                return true;
            }
        });
        this.kitkat_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass3 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(PowerKitActivity.class);
                return true;
            }
        });
        this.explain_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass4 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(ExplainActivity.class);
                return true;
            }
        });
        this.update_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass5 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(UpdateActivity.class);
                return true;
            }
        });
        this.servicedaemon_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass6 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(ServiceDaemonActivity.class);
                return true;
            }
        });
        this.export_syslog_main.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass7 */

            public boolean onPreferenceClick(Preference preference) {
                MainActivity.this.startActivity(LogExportActivity.class);
                return true;
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void startActivity(Class toClass) {
        Intent intent = new Intent(this, toClass);
        intent.setFlags(268435456);
        startActivity(intent);
    }

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
        if (s.equals(getResources().getString(R.string.density_main))) {
            String value = sharedPreferences.getString(getResources().getString(R.string.density_main), "160");
            Log.d(this.TAG, value);
            this.densityManager.setOnDensityChangedListener(new OnDensityChangedListener() {
                /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass8 */

                @Override // com.example.x6.configurationmaintenance.Interface.OnDensityChangedListener
                public void onDensityChanged(boolean isok) {
                    if (!isok) {
                        MessageDialog messageDialog = new MessageDialog(MainActivity.this);
                        messageDialog.setMessage(MainActivity.this.getResources().getString(R.string.set_failed));
                        messageDialog.showDialog();
                        return;
                    }
                    new PowerOffDialog(MainActivity.this).showDialog();
                }
            }, value);
        } else if (s.equals(getResources().getString(R.string.rotate_main))) {
            String value2 = sharedPreferences.getString(getResources().getString(R.string.rotate_main), "0");
            Log.d(this.TAG, value2);
            this.rotateManager.setOnRotateChangedListener(new OnRotateChangedListener() {
                /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass9 */

                @Override // com.example.x6.configurationmaintenance.Interface.OnRotateChangedListener
                public void rotateChanged(boolean isOk) {
                    if (!isOk) {
                        MessageDialog messageDialog = new MessageDialog(MainActivity.this);
                        messageDialog.setMessage(MainActivity.this.getResources().getString(R.string.set_failed));
                        messageDialog.showDialog();
                        return;
                    }
                    new PowerOffDialog(MainActivity.this).showDialog();
                }
            }, value2);
        } else if (s.equals(getResources().getString(R.string.second_rotate_main))) {
            String value3 = sharedPreferences.getString(getResources().getString(R.string.second_rotate_main), "0");
            Log.d(this.TAG, value3);
            this.secondRotateManager.setOnRotateChangedListener(new OnRotateChangedListener() {
                /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass10 */

                @Override // com.example.x6.configurationmaintenance.Interface.OnRotateChangedListener
                public void rotateChanged(boolean isOk) {
                    if (!isOk) {
                        MessageDialog messageDialog = new MessageDialog(MainActivity.this);
                        messageDialog.setMessage(MainActivity.this.getResources().getString(R.string.set_failed));
                        messageDialog.showDialog();
                        return;
                    }
                    new PowerOffDialog(MainActivity.this).showDialog();
                }
            }, value3);
        } else if (s.equals(getResources().getString(R.string.compose_policy))) {
            String value4 = sharedPreferences.getString(getResources().getString(R.string.compose_policy), "6");
            Log.d(this.TAG, value4);
            this.composePolicyManager.setOnComposePolicyChangedListener(new OnRotateChangedListener() {
                /* class com.example.x6.configurationmaintenance.Activity.MainActivity.AnonymousClass11 */

                @Override // com.example.x6.configurationmaintenance.Interface.OnRotateChangedListener
                public void rotateChanged(boolean isOk) {
                    if (!isOk) {
                        MessageDialog messageDialog = new MessageDialog(MainActivity.this);
                        messageDialog.setMessage(MainActivity.this.getResources().getString(R.string.set_failed));
                        messageDialog.showDialog();
                        return;
                    }
                    new PowerOffDialog(MainActivity.this).showDialog();
                }
            }, value4);
        }
    }
}
